import { Component, OnInit } from '@angular/core';
import {
  FormBuilder,
  FormGroup,
  FormControl,
  Validators
} from '@angular/forms';

@Component({
  selector: 'app-edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.scss']
})
export class EditComponent implements OnInit {
  validateForm: FormGroup;
  goodsModalVisible = false;
  pickType = 'goods';

  data = [];
  constructor(private fb: FormBuilder) { }

  ngOnInit() {
    for (let i = 0; i < 5; i++) {
      this.data.push({});
    }

    this.validateForm = this.fb.group({
      name: ['', [Validators.required]],
      task_type: [1, [Validators.required]],
      score: ['', [Validators.required]],
      task_number: ['', [Validators.required]],
      begin_date: ['', [Validators.required]],
      over_date: ['', [Validators.required]],
      pick_id: ['', [Validators.required]],
    });
  }

  getFormControl(name) {
    return this.validateForm.controls[name];
  }

  _refreshStatus($event) {
    this.data.forEach((val, index) => {
      val.checked = false;
    });
  }

  _disabledStartDate = (startValue) => {
    if (!startValue || !this.validateForm.controls[ 'validity_end' ].value) {
      return false;
    }
    return startValue.getTime() >= this.validateForm.controls[ 'validity_end' ].value.getTime();
  }

  _disabledEndDate = (endValue) => {
    if (!endValue || !this.validateForm.controls[ 'validity_start' ].value) {
      return false;
    }
    return endValue.getTime() <= this.validateForm.controls[ 'validity_start' ].value.getTime();
  }

  pickTypeChange($event) {
    console.log($event);
  }
}
